﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using Provider;
using System.Data;

namespace AccessToDataEnergyLibrury
{
   public partial class AccessDataEnergyLibrury
    {
       /// <summary>
        /// Метод возвращает все документы из таблицы Documentation и связаных таблиц
        /// </summary>
        /// <returns></returns>
        public List<ActsWork> GetAllActsWork()
        {
            DataRowCollection searchedRow = this.energyDataSet.actswork.Rows;

            return this.GetRestPartsOfActsWork(searchedRow);
        }

        List<ActsWork> GetRestPartsOfActsWork(DataRowCollection searchedRows)
        {
            if (searchedRows == null || searchedRows.Count == 0)
            {
                return null;
            }
            else
            {
                List<ActsWork> actsworks = new List<ActsWork>();

                foreach (energyzmemDataSet.actsworkRow actworkRow in searchedRows)
                {
                    ActsWork actwork = new ActsWork();
                    actwork.ID = actworkRow.id_actswork;
                    actwork.NameWork = actworkRow.nameWorks;
                    
                    actwork.Cause = actworkRow.cause;
                    actwork.Unit = actworkRow.unit;
                    actwork.AmtFact = actworkRow.amt_fact;
                    actwork.ManHoursUnit = actworkRow.manhoursunit;
                    actwork.LaborCostsEmp = actworkRow.laborcostsemp;


                    if (actworkRow.recordRow != null)
                    {
                        actwork.Record = actworkRow.recordRow.itmesRow.name_item;
                    }
                    else
                    {
                        throw new Exception("Нет данных в таблице Record для Витрати труда робітників");
                    }

                    actsworks.Add(actwork);
                }
                return actsworks;
            }
        }   
   }
}
